package com.spzx.product.controller;

import com.spzx.common.core.constant.Constants;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.exception.ServiceException;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.api.domain.SkuPrice;
import com.spzx.product.api.domain.SkuQuery;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.service.ProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ProductSkuController
 * @Author 波
 * @Date 2024/8/4 11:05
 */
@RestController
@RequestMapping("/productSku")
@Tag(name = "商品sku接口")
public class ProductSkuController extends BaseController {
    @Autowired
    private ProductSkuService productSkuService;

    @Autowired
    private RedissonClient redissonClient;
    @InnerAuth
    @GetMapping("/getTopSale")
    @Operation(summary = "获取销量最好的sku")
    public R<List<ProductSku>> getTopSale() {
        return R.ok(productSkuService.getTopSale());
    }

    @GetMapping("/skuList")
    @InnerAuth
    public R<TableDataInfo> skuList(SkuQuery skuQuery) {
        startPage();
        List<ProductSku> productSkuList = productSkuService.getProductSkuList(skuQuery);
        return R.ok(getDataTable(productSkuList));
    }

    @InnerAuth
    @GetMapping("/getProductSku/{skuId}")
    public R<ProductSku> getProductSku(@PathVariable("skuId") Long skuId) {
        return R.ok(productSkuService.getById(skuId));
    }

    @InnerAuth
    @GetMapping("/getSkuPrice/{skuId}")
    public R<SkuPrice> getSkuPrice(@PathVariable("skuId") Long skuId) {

        return R.ok(productSkuService.getSkuPrice(skuId));
    }

    @InnerAuth
    @GetMapping("/getSkuSpecValueMap/{pid}")
    public R<Map<String,Long>> getSkuSpecValueMap(@PathVariable("pid") Long pid) {
        return R.ok(productSkuService.getSkuSpecValueMap(pid));
    }

    @InnerAuth
    @PostMapping("/getSkuPriceList")
    public R<List<SkuPrice>> getSkuPriceList(@RequestBody  List<Long> skuIdList) {
        return R.ok(productSkuService.getSkuPriceList(skuIdList));
    }


}
